﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QLLopHoc.DoiTuongDuLieu;
using QLLopHoc.XuLyDuLieu;

namespace QLLopHoc
{
    public partial class frmCapNhatGV : Form
    {
        public frmCapNhatGV(DTLopHoc lh)
        {
            InitializeComponent();
            lb_TenLH.Text = lh.TenLopHoc;
            List<DTGiangVien> dsgv = XLGiangVien.LayDSGiangVien();
            cmbGiangVien.Items.AddRange(dsgv.ToArray());
            cmbGiangVien.DisplayMember = "HoTen";
            for (int i = 0; i < dsgv.Count; ++i)
            {
                if (dsgv[i].MSGV == lh.MaGiangVien)
                {
                    cmbGiangVien.SelectedIndex = i;
                    break;
                }
            }
        }

        private void btnBo_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        public DTLopHoc LopHoc
        {
            get
            {
                DTLopHoc lh = new DTLopHoc();
                lh.TenLopHoc = lb_TenLH.Text;
                int idx = cmbGiangVien.SelectedIndex;
                if(idx>-1)
                    lh.MaGiangVien=((DTGiangVien)cmbGiangVien.Items[idx]).MSGV;
                return lh;
            }
        }

        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            if (cmbGiangVien.SelectedIndex == -1)
            {
                MessageBox.Show("Chưa có đủ thông tin.");
                return;
            }
            this.DialogResult = DialogResult.OK;
        }


    }
}
